<?php

namespace teach\controllers;

use teach\service\Order;
use Yii;
use teach\util\helper\ResponseHelper;
use yii\filters\VerbFilter;
use yii\web\Controller;

/**
 * Site controller
 */
class SiteController extends Controller
{

    public $enableCsrfValidation = false;

    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::class,
                'actions' => [
//                    'index' => ['post','get'],
                    '*' => ['post'],
                ],
            ],
        ];
    }

    public function actionError()
    {
    }

    public function actionIndex()
    {

        $request = Yii::$app->request;
        $name = $request->post('name');

        $msg = '';
        $flag = false;
        if (!$name) {
            $msg = 'name 不能为空';
        } else {
            $flag = true;
        }

        if (!$flag) {
            $jsonData = ResponseHelper::buildJsonData(400, $msg);
        } else {
            $page = $request->post('page');
            $page = $page ? $page : 1;
            $map = 'status = 1';
            $orders = new Order();
            $orderList = $orders->orderList($map, $page, $pre_page = 10);
            $jsonData = ResponseHelper::buildJsonData(200,'成功', $orderList);
        }

        return $this->asJson($jsonData);
    }
}
